/**
 * @Title: DictionaryServiceImpl
 * @Package cn.com.yiqi.wsc.service.dictionary.impl
 * @Description: TODO
 * Copyright: Copyright (c) 2016
 * Company: 成都壹柒互动科技有限公司
 * @author 会员系统组-胥钰淋
 * @date 2017/3/6 10:51
 * @version V1.0
 */
package cn.com.yiqi.wsc.service.dictionary.impl;

import cn.com.yiqi.wsc.common.Result;
import cn.com.yiqi.wsc.common.ResultStatusEnum;
import cn.com.yiqi.wsc.dao.dictionary.DictionaryDao;
import cn.com.yiqi.wsc.dao.dictionary.entity.DictionaryEntity;
import cn.com.yiqi.wsc.service.dictionary.DictionaryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 会员系统组-胥钰淋
 * @ClassName: DictionaryServiceImpl
 * @Description: TODO
 * @date 2017/3/6 10:51
 */
@Service
public class DictionaryServiceImpl implements DictionaryService {

    @Autowired
    private DictionaryDao dictionaryDao;

    @Override
    public List<DictionaryEntity> getListByCode(String code) {
        if (StringUtils.isNotEmpty(code)) {
            return dictionaryDao.selectDictionaryByCode(code);
        } else {
            return new ArrayList<>();
        }
    }

    @Override
    public Map<String, String> getMapByCode(String code) {

        Map<String, String> map = new HashMap<>();

        List<DictionaryEntity> entities = getListByCode(code);

        if (!CollectionUtils.isEmpty(entities)) {

            for (DictionaryEntity dictionaryEntity : entities) {
                String key = dictionaryEntity.getValue();
                String value = dictionaryEntity.getName();
                map.put(key, value);
            }

        }
        return map;
    }

    public Result getListByParentCode(String parentCode, String name) {

        Result result = new Result();
        result.setStatus(ResultStatusEnum.操作成功.getCode());

        result.putData("list", dictionaryDao.selectDictionaryByParentCode(parentCode, name));

        return result;
    }


}
